package com.biostime.dingdingbox.modules.db.service;

import java.util.Date;

import org.springframework.stereotype.Service;
import com.biostime.dingdingbox.modules.db.entity.Member;
import com.biostime.dingdingbox.modules.sys.entity.User;

import org.springframework.transaction.annotation.Transactional;

import com.biostime.dingdingbox.common.service.CrudService;
import com.biostime.dingdingbox.modules.db.dao.MemberDao;

/**
 * 会员Service
 * @author chenweicheng
 * @version 2016-06-28
 */
@Service
@Transactional
public class MemberService extends CrudService<MemberDao, Member> {
	
	public Member apiGetMemByForeign(String memberId){
		return dao.apiGetMemByForeign(memberId);
	}
	
	public String apiGetUserId(String memberId){
		Member member = dao.apiGetMemByForeign(memberId);
		if(member != null){
			return member.getId();
		}
		return null;
	}
	
	@Override
	public void save(Member member) {
		if (member.getIsNewRecord()){
			member.setCreateBy(new User("1"));
			member.setUpdateBy(new User("1"));
			member.setCreateDate(new Date());
			member.setUpdateDate(new Date()); 
			dao.insert(member);
		}else{
			dao.update(member);
		}
	}
	
	
}
